<template>
  <div class="launcher" @click="closeLauncher">
    <div class="search-bar">
      <n-input placeholder="搜索" :theme-overrides="inputThemeOverrides">
        <template #prefix>
          <icon-park name="search" color="rgba(200,200,200,0.8)" :stroke-width="4" />
        </template>
      </n-input>
    </div>
    <div class="application-items">
      <n-carousel draggable :loop="false">
        <div v-for="(applications, index) in applicationPages" :key="index" class="page">
          <div class="item" v-for="application in applications" :key="application.id">
            <icon :path="application.info.icon" />
            <div>
              {{ application.info.name }}
            </div>
          </div>
        </div>
      </n-carousel>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { NCarousel, NInput } from "naive-ui"
import IconPark from "../../common/IconPark.vue"
import { useInputThemeOverrides } from "./index"
import { useApplicationStore } from "@/stores/application"
import { computed } from "vue"
import * as _ from "lodash"
import Icon from "../../applications/icon/Icon.vue"
import { storeToRefs } from "pinia"

const inputThemeOverrides = useInputThemeOverrides()

const applicationStore = useApplicationStore()

const { applicationsContext } = storeToRefs(applicationStore)

const applicationPages = computed(() => {
  return _.chunk([...applicationsContext.value.allApplications().values()], 35)
})

defineProps({
  closeLauncher: {
    type: Function,
    required: true
  }
})
</script>

<style scoped lang="scss">
.launcher {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background: rgba(150, 150, 150, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  .search-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1rem;

    .n-input {
      width: 2rem;
      background-color: transparent;
    }
  }

  .application-items {
    height: calc(100% - 1rem - var(--dock-size));
    padding: 0 1rem 0.2rem 1rem;

    .page {
      display: flex;
      align-items: center;
      justify-content: flex-start;

      .item {
        display: flex;
        align-items: center;
        justify-content: space-around;
        flex-direction: column;
        color: white;
        width: 1rem;
        height: 1rem;

        .application-icon {
          --application-icon-size: 0.6rem;
        }
      }
    }
  }
}
</style>
